package com.hluck.navigation2

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.navigation.Navigation
import com.hluck.navigation2.databinding.FragmentHomeBinding


class HomeFragment : Fragment() {

    private lateinit var mBinding:FragmentHomeBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false)
        // Inflate the layout for this fragment
        return mBinding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        mBinding.btnSubmit.setOnClickListener {
            val text = mBinding.editTextText.text?:"empty Message."
            val controller = Navigation.findNavController(it)
            val bundle = Bundle()
            bundle.putString("message", text.toString())
            controller.navigate(R.id.action_homeFragment_to_detailFragment,bundle)
        }

    }


}